<?php
session_start();
$title="แสดงรายการจองทั้งหมด";
include ('header-admin.php');

$type;
if(isset($_GET['type'])){
	$type = $_GET['type'];
}else{
	$type="1";
}

$inputDate = $_POST['inputDate'];

list($bYear, $bMonth, $bDay) = explode("-",substr($inputDate,0,10));
list($eYear, $eMonth, $eDay) = explode("-",substr($inputDate,11,10));

$bDate = mktime(0,0,0,$bMonth,$bDay,$bYear);
$eDate = mktime(0,0,0,$eMonth,$eDay,$eYear);

$reserv_begin = date("Y-m-d", $bDate);
$reserv_end = date("Y-m-d", $eDate);

$userID=$_SESSION["HBD_USER"];
$countTopic=0;
if($userID == 1){
?>
<script language="javascript">
	function ConfirmChoice(id){
	answer = confirm("คุณแน่ใจว่าจะลบ ?")
		if (answer !=0)
			location = "doDeleteNews.php?newsID=" + id;
	}
</script>
<?}?>
<div id="center-block" class="main-content">
<img src="img/booking.png"/ id="img-block-content">
<div id="content-title-right"><!--
		<h2><?=$menu[$type-1]?></h2>
		--><span class="caption">&nbsp;&nbsp;&nbsp;แสดงรายการห้องพักที่สามารถจองได้ ภายในระยะเวลา <? echo "<b>".$reserv_begin."</b>";?> ถึง <? echo "<b>".$reserv_end."</b>";?></span>
		<span class="right-button">
				</span>
	</div>

	<hr>
	<table summary="webboard about Datastrucutre learning" id="table">
		<thead>
		<tr class="odd">
			<th scope="col" abbr="reserv_id">หมายเลขห้อง</th>
			<th scope="col" abbr="reserv_id">ขนาดห้อง</th>
			<th scope="col" abbr="reserv_id">ชนิดห้อง</th>
			<th scope="col" abbr="reserv_id">ราคา</th>
		</tr>	
		</thead>
		<tbody>
		<?
		$current = date("Y-m-d",strtotime("Today"));


	   $sql2="SELECT room_id,roomsize_name,roomtype_name,room_cost FROM resort
	   INNER JOIN roomtype ON (resort.roomtype_id = roomtype.roomtype_id)
	   INNER JOIN roomsize ON (resort.roomsize_id = roomsize.roomsize_id)
WHERE room_id NOT IN(SELECT DISTINCT reservation.room_id
FROM reservation WHERE reserv_status != '2' AND (`reserv_end` > '$reserv_begin' AND `reserv_end` <= '$reserv_end'
OR `reserv_begin` >= '$reserv_begin' AND `reserv_begin` <= '$reserv_end'))
ORDER BY roomtype_name,room_id ASC";

	$result = mysql_query($sql2);
	while ($rs = mysql_fetch_array($result)){

		echo '<tr>';
		echo '<td>' . $rs['room_id'] . '</a>';
		echo '<td>' . $rs['roomsize_name'] . '</a>';
		echo '<td>' . $rs['roomtype_name'] . '</a>';
		echo '<td>' . $rs['room_cost'] . '</a>';
		echo '</tr>';
}
	?>
		</tbody>

	</table>
	</div>

<?
include ('footer.php');
?>